package com.itheima.health.h5.controller;

import com.itheima.health.entity.Result;
import com.itheima.health.pojo.Order;
import com.itheima.health.pojo.Setmeal;
import com.itheima.health.service.OrderService;
import com.itheima.health.service.SetmealService;
import com.itheima.health.utils.redis.RedisUtil;
import com.itheima.health.utils.resources.RedisConstant;
import com.itheima.health.utils.resources.RedisMessageConstant;
import com.itheima.health.utils.sms.SmsUtils;
import com.itheima.health.utils.sms.ValidateCodeUtils;
import com.itheima.health.vo.SetmealVO;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;

@RestController
public class OrderControler {

    @Reference
    private OrderService orderService;

    @GetMapping("order/sendCode/{telephone}")
    public Result telephone(@PathVariable("telephone") String telephone) {
        String code = ValidateCodeUtils.generateValidateCode(4);
//        SmsUtils.validUserTelephone(telephone,code);
//        SmsUtils.orderSuccessMessage(telephone,code);
        RedisUtil.set(RedisMessageConstant.SENDTYPE_ORDER +telephone,code,90, TimeUnit.MINUTES);
        return new Result(code);
    }

    @PostMapping("order/add")
    public Result add(@RequestBody Map map){

    return new Result(orderService.add(map));
    }

    @GetMapping("orderSuccess/findById")
    public Result findById(@RequestParam("id")int id){
      Map map= orderService.findById(id);
        System.out.println("order = " + map);
        return new Result(map);
    }
}